<?php
namespace app\traits;

trait ModelTrait
{
    public static $error;

    public function getLastError()
    {
        if (!empty(static::$error)) {
            return static::$error;
        }
        $errors = $this->getMessages(false);
        while (is_array($errors)) {
            $errors = array_pop($errors);
        }
        static::$error = $errors;
        return static::$error;
    }
}